package com.example.stock.task;

import com.example.stock.business.*;
import com.example.stock.util.DataUtil;
import com.example.stock.util.StatisticDataUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Log4j2
@Component
public class DataInitTask {

    @Value("${spring.profiles.active}")
    private String env;

    private boolean isDev() {
        return env.equals("dev");
    }

    @Async
    public void genArticleData() {
        DataUtil.getArticleData();
        log.info("文章数据初始化完毕");
    }

    @Async
    public void genMonthLpUpData() {
        StatisticDataUtil.getMonthLpUp();
        log.info("突破10分位点数据初始化完成");
    }

    @Async
    public void genMonthLpDownData() {
        StatisticDataUtil.getMonthLpDown();
        log.info("跌破10分位点数据初始化完成");
    }

    @Async
    public void genFinanceData() {
        DataUtil.getFinanceData();
        log.info("财务数据初始化完毕");
    }

    @Async
    public void genLevelPointDecreaseData() {
        StatisticDataUtil.getLevelPointDecrease();
        log.info("分位点跌幅数据初始化完毕");
    }

    @Async
    public void genYearPctStatData() {
        DataUtil.getYearPctStatData();
        log.info("年涨跌数据初始化完毕");
    }

    @Async
    public void genWeekLpUpData() {
        StatisticDataUtil.getWeekLpUpData();
        log.info("周分位点突破数据");
    }

    @Async
    public void genWeekLpNewHighData() {
        StatisticDataUtil.getWeekLpNewHighs();
        log.info("周分位点突破100数据");
    }

    @Async
    public void genMonthLpNewHighData() {
        StatisticDataUtil.getMonthLpNewHigh();
        log.info("月分位点突破100数据");
    }

    @Async
    public void genWuguData() {
        DataUtil.getWuguList();
        log.info("吾股数据初始化完毕");
    }

    @Async
    public void genMinYearPctData() {
        DataUtil.getMinYearPctList();
        log.info("最小年化数据初始化完毕");
    }

    @Autowired
    StockHoldBusiness stockHoldBusiness;

    @Async
    public void initStockHold() {
        if  (isDev()) {
            stockHoldBusiness.getHoldStocks();
            log.warn("init stock hold");
        }
    }

    @Autowired
    LastedOperationBusiness lastedOperationBusiness;

    @Async
    public void initLastOpt() {
        if  (isDev()) {
            lastedOperationBusiness.getLastedOperation("ALL");
            log.warn("init last opt");
        }
    }

    @Autowired
    WuguBusiness wuguBusiness;

    @Async
    public void initWugu() {
        if (isDev()) {
            wuguBusiness.getWuguDTO();
            log.warn("init wugu");
        }
    }

    @Autowired
    WeekLowStaBusiness weekLowStaBusiness;

    @Async
    public void initWeekLowSta() {
        if (isDev()) {
            weekLowStaBusiness.getWeekLowSta();
            log.warn("init low sta");
        }
    }
}